import axios from './eco/base'

/**
 * 功能: 获取通用控制列表
 * condition
 */
export const list = (data) => {
  let params = {
    pageNo: 1,
    pageSize: 10,
    ...data
  }
  Object.keys(params).forEach((key) => {
    if (params[key] === '') {
      delete params[key]
    }
  })
  return axios.post('/zn-e-library/dataFormExtendAttr/list', params).then(res => {
    return res
  })
}

/**
 * 功能: 获取通用控制详情
 */
export const deleteByUserId = (data) => {
  let params = {
    pageNo: 1,
    pageSize: 10,
    ...data
  }
  Object.keys(params).forEach((key) => {
    if (params[key] === '') {
      delete params[key]
    }
  })
  return axios.post('/zn-e-library/dataFormExtendAttr/get/' + data.condition.formId, data).then(res => {
    return res
  })
}

/**
 * 功能: 查询表单填报权限
 */
export const purviewList = (data) => {
  let params = {
    pageNo: 1,
    pageSize: 10,
    ...data
  }
  Object.keys(params).forEach((key) => {
    if (params[key] === '') {
      delete params[key]
    }
  })
  return axios.post('/zn-e-library/purview/list', data).then(res => {
    return res
  })
}
/**
 * 功能: 查询表单填报权限
 * roleType: 0：机构，1：用户，2：班级
 */
export const purviewSave = (data) => {
  let params = {
    ...data
  }
  Object.keys(params).forEach((key) => {
    if (params[key] === '') {
      delete params[key]
    }
  })
  return axios.post('/zn-e-library/purview/save', data).then(res => {
    return res
  })
}
/**
 * 功能: 查询表单协作权限
 */
export const termPurviewList = (data) => {
  let params = {
    pageNo: 1,
    pageSize: 10,
    ...data
  }
  Object.keys(params).forEach((key) => {
    if (params[key] === '') {
      delete params[key]
    }
  })
  return axios.post('/zn-e-library/termPurview/list', data).then(res => {
    return res
  })
}
/**
 * 功能: 查询表单协作权限
 * objectId 机构Id，用户ID
 * roleType: 0：机构，1：用户，2：班级
 */
export const termPurviewSave = (data) => {
  let params = {
    ...data
  }
  Object.keys(params).forEach((key) => {
    if (params[key] === '') {
      delete params[key]
    }
  })
  return axios.post('/zn-e-library/termPurview/save', data).then(res => {
    return res
  })
}

/**
 * 功能: 检查当前用户有无填报权限
 * roleType: 0：机构，1：用户，2：班级
 */
export const checkHasPurview = (data) => {
  let params = {
    ...data
  }
  Object.keys(params).forEach((key) => {
    if (params[key] === '') {
      delete params[key]
    }
  })
  return axios.post('/zn-e-library/purview/checkHasPurview', data).then(res => {
    return res
  })
}
